package std.bank;

public class AccountImpl implements Account
{
	double balance = 0;
	String name = "";

	public AccountImpl(String name, double balance)
	{
		this.balance = balance;
		this.name = name;
	}

	@Override
	public synchronized void deposit(double amount)
	{
		if (amount > 0)
		{
			balance += amount;
		}
	}

	@Override
	public boolean equals(Object o)
	{
		if (o == this)
		{
			return true;
		}
		if (o == null || o.getClass() != getClass())
		{
			return false;
		}

		Account a = (Account) o;
		return a.getName().equals(getName());
	}

	@Override
	public double getBalance()
	{
		return balance;
	}

	@Override
	public String getName()
	{
		return name;
	}

	@Override
	public String toString()
	{
		return "[Account: " + name + ": " + balance + "]";
	}

	@Override
	public synchronized void withdraw(double amount)
	{
		if (amount > 0)
		{
			balance -= amount;
		}
	}

}
